package com.bjpowernode.singleton;

import java.util.concurrent.CountDownLatch;

/**
 * @ClassName TestEfficiency
 *
 * @Author Cat
 */
public class TestEfficiency {

    public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();

        int threadNum = 10;
        final CountDownLatch countDownLatch = new CountDownLatch(threadNum);

        for (int i = 0; i < threadNum; i++) {
            //创建10个线程
            new Thread(() -> {
                for (int j = 0; j < 10000000; j++) {
                    //Object o1 = Singleton01.getInstance(); //51ms
                    //Object o2 = Singleton02.getInstance(); //72ms
                    //Object o3 = Singleton03.getInstance(); //5316ms
                    //Object o4 = Singleton04.getInstance(); //91ms
                    //Object o5 = Singleton05.getInstance(); //93ms
                    //Object o6 = Singleton06.getInstance(); //60ms
                    //Object o7 = Singleton07.getInstance(); //51ms
                    Object o8 = Singleton08.INSTANCE; //45ms
                }
                countDownLatch.countDown();
            }).start();
        }
        countDownLatch.await();//main方法阻塞，直到计数器变为0才会继续执行
        long end = System.currentTimeMillis();
        System.out.println("总耗时：" + (end - start) + "ms");

        java.lang.Runtime t;
    }
}